package day6

import org.apache.spark.sql.{DataFrame, SparkSession, functions}

object Test3_DSL {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder().master("local[*]").appName("cheshi1").getOrCreate()
    val df: DataFrame = spark.read.json("file:///d:\\data\\a.json")

    import spark.implicits._

    df.select($"name",$"age").withColumn("age2",functions.lit(1)).withColumn("age3",$"age"+5)

    df.show()

    df.where($"age">20).show
    df.groupBy($"age").count.show

    df.withColumn("x1",
                  functions.when($"age"<18,"未成年").when($"age"<60,"成年").otherwise("老年"))
                  .show()

    spark.stop()
  }
}
